﻿<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" class="hb-loaded">

	<head>
		<meta charset="utf-8">
		<title>会员注册</title>
		<link href="css/style.css" type="text/css" rel="stylesheet" />
	</head>

	<body>
		<div class="wrap">
			<!-- start of 头部导航-->
			<div class="head_top">
				<div class="head clearfix">
					<!--头部左边-->
					<div class="topLeft left">
						<a href="index" title="Darry Ring">
							<img width="186" height="42" src="images/logo_01.png ">
						</a>
						<span>求婚钻戒领导品牌</span>
					</div>
					<!--头部左边end-->
					<!--头部右边-->
					<ul class="topRight right">
						<li>国际权威认证</li>
						<li class="tr_2">15天无理由退换</li>
						<li class="tr_3">终身保养</li>
					</ul>
					<!--头部左边end-->
				</div>
			</div>
			<!--end of 头部导航-->
			<!-- starto of container -->
			<div class="container">
				<!--中间内容-->
				<div class="cmain ddd">
					<!--内容右边-->
					<div class="cort-right right">
						<div class="r_bg"></div>
						<!--登陆框内-->
						<div class="cr_border">
							

							<form method="post" action="register" class="form_first">
								<input type="hidden" value="1" name="type">
								<input type="hidden" value="login" name="forward">
								<input type="hidden" value="H6mY5VyS" name="skey">
								<div style="" class="photo_show">
									<div th:if="${errorMsg!=null}" class="ts_wrong">
										<span th:text="${errorMsg}" id="wrong"></span>
									</div>
									<!--手机-->
									<div class="the_input">
										<span class="member"></span>
										<input type="text" placeholder="请输入手机号码" class="al_Input dr_photo" value="" name="uphone">
									</div>
									<!--手机end-->
									<!--密码-->
									<div class="the_input ">
										<span class="pw"></span>
										<input type="password" placeholder="请输入密码" maxlength="21" class="al_Input dr_photo" value="" name="">
									</div>
									<!--密码end-->
									<!--密码-->
									<div class="the_input ">
										<span class="pw"></span>
										<input type="password" placeholder="确认密码" maxlength="21" class="al_Input dr_photo" value="" name="upassword">
									</div>
									<!--密码end-->


									<!--其他合作-->
									<div class="other_hz">
										<input type="submit" value="立即注册" id="mobile_reg" class="up">
									</div>
									<!--其他合作end-->
								</div>
							</form>
							<!--手机注册end-->
						</div>
						<!--登陆框内end-->
					</div>
					<!--内容右边end-->
				</div>
				<!--中间内容end-->
			</div>
			<!-- end of container -->

			<!--底部end-->
			<div class="cmain bc_yz">
				<div class="db_cort">
					<p> Copyright &copy; 2017 winner winner,chickdinner ！！团队 All Rights Reserved. 闽ICP备11012085号-2.ICP经营许可证闽B2-20140279 </p>
					<p> 中国互联网违法信息举报中心 | 中国公安网络110报警服务 | 本网站提供所售商品的正式发票 </p>
				</div>
			</div>

			<script src="js/jquery.js" type="text/javascript"></script>
			<script type="text/javascript">
				$(function() {
					//切换tab
					$(".tits .ph").click(function(event) {
						$(this).addClass('focus').siblings().removeClass('focus')
						$(".photo_show").eq(0).show()
						$(".photo_show").eq(1).hide()
					});

					$(".tits .em").click(function(event) {
						$(this).addClass('focus').siblings().removeClass('focus')
						$(".photo_show").eq(1).show()
						$(".photo_show").eq(0).hide()
					});

					//验证参数
					$('.up').click(function() {
						$('.ts_wrong').remove();
						$('.al_Input').removeClass('error');
						//判断是邮箱还是手机
						if($('.em').hasClass('focus')) {
							//邮箱登录
							var email = $('input[name="email"]').val();
							if(isNull(email)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入邮箱！</span></div>';
								$('input[name="email"]').parent().after(notice);
								$('input[name="email"]').addClass('error');
								return false;
							}

							if(!isEmail(email)) {
								var notice = '<div class="ts_wrong"><span id="wrong">邮箱格式错误 请重新输入！</span></div>';
								$('input[name="email"]').parent().after(notice);
								$('input[name="email"]').addClass('error');
								return false;
							}

							var pwd = $('input[name="email_pwd"]').val();
							if(isNull(pwd)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入密码！</span></div>';
								$('input[name="email_pwd"]').parent().after(notice);
								$('input[name="email_pwd"]').addClass('error');
								return false;
							}

							if(pwd.length < 6) {
								var notice = '<div class="ts_wrong"><span id="wrong">密码长度为6~21个字符！</span></div>';
								$('input[name="email_pwd"]').parent().after(notice);
								$('input[name="email_pwd"]').addClass('error');
								return false;
							}

							var pwd_confirm = $('input[name="email_pwd_confirm"]').val();
							if(isNull(pwd_confirm)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入确认密码！</span></div>';
								$('input[name="email_pwd_confirm"]').parent().after(notice);
								$('input[name="email_pwd_confirm"]').addClass('error');
								return false;
							}

							if(pwd != pwd_confirm) {
								var notice = '<div class="ts_wrong"><span id="wrong">密码与确认密码不一致 请重新输入！</span></div>';
								$('input[name="email_pwd_confirm"]').parent().after(notice);
								$('input[name="email_pwd_confirm"]').addClass('error');
								return false;
							}

							var code = $('input[name="email_code"]').val();
							if(isNull(code)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入验证码！</span></div>';
								$('input[name="email_code"]').parent().after(notice);
								$('input[name="email_code"]').addClass('error');
								return false;
							}

							if(!$('input[name="email_check"]').is(':checked')) {
								var notice = '<div class="ts_wrong"><span id="wrong">请阅读并同意用户注册协议！</span></div>';
								$('input[name="email_check"]').parent().parent().after(notice);
								return false;
							}

							// $('#mobile_reg').click(ag_Reg_click_Mobile);
							// 注册统计
							ag_Reg_click_Email();

							//检测邮箱是否使用过
							$.ajax({
								type: "POST",
								url: "/sign/validEmail",
								data: "email=" + email,
								success: function(msg) {
									if(msg == 1) {
										var notice = '<div class="ts_wrong"><span id="wrong">该邮箱已被注册！</span></div>';
										$('input[name="email"]').parent().after(notice);
										$('input[name="email"]').addClass('error');
										return false;
									} else {
										$.ajax({
											type: "POST",
											url: "/sign/validEmailCode",
											data: "code=" + code,
											success: function(msg) {
												if(msg == 1) {
													var notice = '<div class="ts_wrong"><span id="wrong">验证码错误！</span></div>';
													$('.ts_wrong').remove();
													$('input[name="email_code"]').parent().after(notice);
													$('input[name="email_code"]').addClass('error');
													return false;
												} else {
													$('.form_second').submit();
												}
											}
										});
									}
								}
							});

						}

						if($('.ph').hasClass('focus')) {
							//手机登录
							var mobile = $('input[name="mobile"]').val();
							if(isNull(mobile)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入手机号码！</span></div>';
								$('input[name="mobile"]').parent().after(notice);
								$('input[name="mobile"]').addClass('error');
								return false;
							}

							if(!checkMobile(mobile)) {
								var notice = '<div class="ts_wrong"><span id="wrong">手机号码格式错误 请重新输入！</span></div>';
								$('input[name="mobile"]').parent().after(notice);
								$('input[name="mobile"]').addClass('error');
								return false;
							}

							var code = $('input[name="mobile_code"]').val();
							if(isNull(code)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入验证码！</span></div>';
								$('input[name="mobile_code"]').parent().after(notice);
								$('input[name="mobile_code"]').addClass('error');
								return false;
							}

							var pwd = $('input[name="mobile_pwd"]').val();
							if(isNull(pwd)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入密码！</span></div>';
								$('input[name="mobile_pwd"]').parent().after(notice);
								$('input[name="mobile_pwd"]').addClass('error');
								return false;
							}

							if(pwd.length < 6) {
								var notice = '<div class="ts_wrong"><span id="wrong">密码长度为6~21个字符！</span></div>';
								$('input[name="mobile_pwd"]').parent().after(notice);
								$('input[name="mobile_pwd"]').addClass('error');
								return false;
							}

							var pwd_confirm = $('input[name="mobile_pwd_confirm"]').val();
							if(isNull(pwd_confirm)) {
								var notice = '<div class="ts_wrong"><span id="wrong">请输入确认密码！</span></div>';
								$('input[name="mobile_pwd_confirm"]').parent().after(notice);
								$('input[name="mobile_pwd_confirm"]').addClass('error');
								return false;
							}

							if(pwd != pwd_confirm) {
								var notice = '<div class="ts_wrong"><span id="wrong">密码与确认密码不一致 请重新输入！</span></div>';
								$('input[name="mobile_pwd_confirm"]').parent().after(notice);
								$('input[name="mobile_pwd_confirm"]').addClass('error');
								return false;
							}

							if(!$('input[name="mobile_check"]').is(':checked')) {
								var notice = '<div class="ts_wrong"><span id="wrong">请阅读并同意用户注册协议！</span></div>';
								$('input[name="mobile_check"]').parent().parent().after(notice);
								return false;
							}

							//检测手机号码是否使用过
							$.ajax({
								type: "POST",
								url: "/sign/validMobile",
								data: "mobile=" + mobile,
								success: function(msg) {
									if(msg == 1) {
										var notice = '<div class="ts_wrong"><span id="wrong">该手机号码已被注册！</span></div>';
										$('input[name="mobile"]').parent().after(notice);
										$('input[name="mobile"]').addClass('error');
										return false;
									} else {
										$.ajax({
											type: "POST",
											url: "/sign/validMobileCode",
											data: "code=" + code,
											success: function(msg) {
												if(msg == 1) {
													var notice = '<div class="ts_wrong"><span id="wrong">验证码错误！</span></div>';
													$('input[name="mobile_code"]').parent().after(notice);
													$('input[name="mobile_code"]').addClass('error');
													return false;
												} else {
													// 手机统计
													ag_Reg_click_Mobile();
													$('.form_first').submit();
												}
											}
										});
									}
								}
							});

						}
					});

					//发送短信验证码
					var InterValObj; //timer变量，控制时间
					var count = 120; //间隔函数，1秒执行
					var curCount; //当前剩余秒数
					$('.mobile_action').click(function() {
						$('.ts_wrong').remove();
						$('.al_Input').removeClass('error');
						var mobile = $('input[name="mobile"]').val();
						if(isNull(mobile)) {
							var notice = '<div class="ts_wrong"><span id="wrong">请输入手机号码！</span></div>';
							$('input[name="mobile"]').parent().after(notice);
							$('input[name="mobile"]').addClass('error');
							return false;
						}

						if(!checkMobile(mobile)) {
							var notice = '<div class="ts_wrong"><span id="wrong">手机号码格式错误 请重新输入！</span></div>';
							$('input[name="mobile"]').parent().after(notice);
							$('input[name="mobile"]').addClass('error');
							return false;
						}

						//检测手机号码是否使用过
						var is_used = false;
						$.ajax({
							type: "POST",
							url: "/sign/validMobile",
							data: "mobile=" + mobile,
							success: function(msg) {
								if(msg == 1) {
									var notice = '<div class="ts_wrong"><span id="wrong">该手机号码已被注册！</span></div>';
									$('input[name="mobile"]').parent().after(notice);
									$('input[name="mobile"]').addClass('error');
									is_used = true;
								} else {
									//设置button效果，开始计时
									curCount = count;
									//设置button效果，开始计时
									$(".mobile_action").attr("disabled", "true");
									$(".mobile_action").val(curCount + "秒后可重新获取验证码");
									InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次

									var skey = $('input[name="skey"]').val();
									//向后台发送处理数据
									$.ajax({
										type: "POST", //用POST方式传输
										url: '/sign/sendSms', //目标地址
										data: "mobile=" + mobile + "&skey=" + skey,
										success: function(msg) {

										}
									});
								}
							}
						});

						function SetRemainTime() {
							if(curCount == 0) {
								window.clearInterval(InterValObj); //停止计时器
								$(".mobile_action").removeAttr("disabled"); //启用按钮
								$(".mobile_action").val("获取验证码");
								code = ""; //清除验证码。如果不清除，过时间后，输入收到的验证码依然有效 
							} else {
								curCount--;
								$(".mobile_action").val(curCount + "秒后可重新获取验证码");
							}
						}
					});

				});

				$(document).keyup(function(event) {
					if(event.keyCode == 13) {
						if($('.ph').hasClass('focus')) {
							$('#mobile_reg').click(ag_Reg_click_Mobile);
						}
						if($('.em').hasClass('focus')) {
							$('#email_reg').click(ag_Reg_click_Email);
						}
					}
				});
			</script>

	</body>

</html>